package com.lms.config;

import com.lms.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: 网站相关配置
 * @author: L-B-S
 * @Date: 2021/3/4 15:43
 * @modified_By:
 * @Version: 0.0$
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 配置拦截器
     *
     * @param registry 注册对象
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new LoginInterceptor())
                // 拦截所有
                .addPathPatterns("/**")
                // 对部分路径不进行拦截
                .excludePathPatterns("/", "/admin/**", "/css/**", "/fonts/**", "/images/**",
                        "/js/**", "/lib/**", "/wx/**");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .allowedHeaders("*")
                .maxAge(3600);
    }
}
